import java.util.*;

public class test5 {
    //力扣 LCR 033.字母异位词分组

    public List<List<String>> groupAnagrams(String[] strs) {
        Map<String, List<String>> hash = new HashMap<>();
        //先把所有的字母异位词分组
        for(String str:strs){
            char[] chars = str.toCharArray();
            Arrays.sort(chars);
            String key = new String(chars);
            if(!hash.containsKey(key)){
                hash.put(key,new ArrayList());
            }
            hash.get(key).add(str);
        }
        //提取结果
        return new ArrayList(hash.values());
    }


    //判断是否未异位词
    public static boolean isTrue(String str1,String str2){
        if(str1.length()!= str2.length())  return false;
        char[] chars1 = str1.toCharArray();
        char[] chars2 = str2.toCharArray();
        for(int i = 0;i<chars1.length-1;i++){
            for(int j = 0;j<chars1.length-i-1;j++){
                if(chars1[j]>chars1[j+1]){
                    char temp = chars1[j];
                    chars1[j] = chars1[j+1];
                    chars1[j+1] = temp;
                }
                if(chars2[j]>chars2[j+1]){
                    char temp = chars2[j];
                    chars2[j] = chars2[j+1];
                    chars2[j+1] = temp;
                }
            }
        }
        for(int i = 0;i<chars1.length;i++){
            if(chars1[i]!=chars2[i]){
                return false;
            }
        }
        System.out.println(chars1.toString());
        String str = new String(chars1.toString());
        System.out.println(str);
        return true;

    }
}
